import os

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node

def generate_launch_description():

    model_folder = "grassland"
    model_folder = "turtlebot3_burger"

    # urdf_path = os.path.join(
    #     get_package_share_directory('mower_gazebo'),
    #     'models',
    #     model_folder, 
    #     'model.sdf')
    urdf_path = os.path.join(
        get_package_share_directory('mower_gazebo'),
        'models',
        "fishrobot", 
        'fishrobot.urdf')
    
    print(urdf_path)
    

    x_pose = LaunchConfiguration('x_pose', default='0.0')
    y_pose = LaunchConfiguration('y_pose', default='0.0')

    declare_x_position_cmd = DeclareLaunchArgument(
        'x_pose',
        default_value='0.0',
        description='Robot x position')
    declare_y_position_cmd = DeclareLaunchArgument(
        'y_pose',
        default_value='0.0',
        description='Robot y position')

    start_gazebo_ros_spawner_cmd = Node(
        package='gazebo_ros',
        executable='spawn_entity.py',
        name='spawn_entity',
        output='screen',
        arguments=[
            '-entity', "turtlebot3_burger",
            '-file', urdf_path,
            '-x', x_pose,
            '-y', y_pose,
            '-z', '0.01'],
            )
    
    ld = LaunchDescription()

    ld.add_action(declare_x_position_cmd)
    ld.add_action(declare_y_position_cmd)   

    ld.add_action(start_gazebo_ros_spawner_cmd)

    return ld

#     # '-topic', '/robot_description',
#     # '-file', urdf_path, 不能同时使用


# def generate_launch_description():
    

#     # GAZEBO_MODEL_PATH has to be correctly set for Gazebo to be able to find the model
#     spawn_entity = Node(package='gazebo_ros', executable='spawn_entity.py',
#                         arguments=['-entity', 'demo', '-database', 'double_pendulum_with_base'],
#                         output='screen')

#     return LaunchDescription([
        

#         spawn_entity,
#     ])